package com.polaris.live.widget.refresh

import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import android.view.ViewGroup
import android.widget.RelativeLayout
import androidx.annotation.ColorInt
import androidx.annotation.DrawableRes
import com.polaris.live.common.ext.dp
import com.polaris.live.common.ext.setOnSingleClickListener
import com.polaris.live.databinding.WidgetItemDressUpEmptyBinding

/**
 * 装扮空数据
 *
 * @author Created by lucas on 2023/10/16 20:42
 * @since 1.0.0
 */
class DressUpEmptyView(context: Context, attrs: AttributeSet? = null) : RelativeLayout(context, attrs) {

    private val mBinding = WidgetItemDressUpEmptyBinding.inflate(LayoutInflater.from(context), this)

    fun setEmptyTip(
        @DrawableRes img: Int,
        tip: String,
        @ColorInt color: Int? = null,
        width: Int? = null,
        height: Int? = null,
    ) {
        mBinding.bg.setImageResource(img)
        mBinding.text.text = tip
        color?.let { mBinding.text.setTextColor(it) }

        if (width != null && height != null) {
            val layoutParams = mBinding.bg.layoutParams as ViewGroup.LayoutParams
            layoutParams.width = width.dp
            layoutParams.height = height.dp
            mBinding.bg.layoutParams = layoutParams
        }
    }

    fun setClickListener(clickListener: () -> Unit) {
        mBinding.go.setOnSingleClickListener {
            clickListener.invoke()
        }
    }
}